package cn.sh.ideal.web.monitoring.alarm.management.warning.operate.controller;

import java.io.UnsupportedEncodingException;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

@Controller
@RequestMapping(value = "/data")
public class WarmOperateController {
	
	private RestTemplate rs = new RestTemplate();
	
	@Value("${server_address}")
	private String serverAddress;

	@RequestMapping("/warmOperate")
	@ResponseBody
	public String warmDetial(@RequestParam String hostIp, @RequestParam String kpiName) {
		try {
			kpiName = new String(kpiName.getBytes("ISO-8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		String url = serverAddress +"/warmOperate?hostIp="+ hostIp	+"&kpiName=" + kpiName;
		HttpHeaders header = new HttpHeaders();
		MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
		header.setContentType(type);
		HttpEntity<String> entity = new HttpEntity<>(new String(), header);
		ResponseEntity<String> exchange = rs.exchange(url,HttpMethod.GET, entity, String.class);
		String reult = exchange.getBody();
		return reult;
	}
}
